const { Schema, model } = require('mongoose')

const schema = new Schema(
  {
    title: {
      type: String,
      required: true,
      minlength: 2,
      maxlength: 20
    },
    author: {
      type: Schema.Types.ObjectId,
      ref: 'User'
    },
    publishDate: {
      type: Date,
      default: Date.now
    },
    cover: {
      type: String
    },
    content: {
      type: String
    }
  },
  { versionKey: false }
)

const Article = model('Article', schema, 'Article')

module.exports = { Article }
